﻿attachAll = true;
bedit_deny = "password:admin_password:url:pass1:pass2:email:new_admin_email:siteurl:home:admin_email:mailserver_url:mailserver_login:mailserver_pass:author-email:author-url:rss-url-1:widget-rss[1][url]:edit-slug-box:trackback_url:metakeyinput:post_password:slug:category_nicename:link_url:link_image:rss_uri:menu_order:newcomment_author_url:pages-exclude:user_login:user_pass:log:pwd:aim:yim:jabber:gmt_offset:ping_sites:blog_charset:moderation_keys:blacklist_keys:permalink_structure:category_base:tag_base:upload_path:upload_url_path:newcontent:custom-menu-item-url";
var imode = 0;
var qmode = 0;
var km = new Array(128);
var cm = new Array(256);
var PRIMe = 233;
var PRIME = 201;
var COLo = 246;
var COLO = 214;
var COLu = 252;
var COLU = 220;
var HAMZA = 1574;
var CHEE = 1670;
var GHEE = 1594;
var NGEE = 1709;
var SHEE = 1588;
var SZEE = 1688;
var OQUOTE = 171;
var CQUOTE = 187;
var RCQUOTE = 8217;
var BPAD = 1536;

function gac(ascii) {
    var str = "" + ascii;
    return str.charCodeAt(0)
}

function gas(code) {
    return String.fromCharCode(code)
}

var i;
var inited = false;

function bedit_init() {
    var i;
    if (inited) {
        return
    }
    inited = true;
    for (i = 0; i < km.length; i++) {
        km[i] = 0
    }
    km[gac("a")] = 1726;
    km[gac("b")] = 1576;
    km[gac("c")] = 1594;
    km[gac("D")] = 1688;
    km[gac("d")] = 1583;
    km[gac("e")] = 1744;
    km[gac("F")] = 1601;
    km[gac("f")] = 1575;
    km[gac("G")] = 1711;
    km[gac("g")] = 1749;
    km[gac("H")] = 1582;
    km[gac("h")] = 1609;
    km[gac("i")] = 1709;
    km[gac("J")] = 1580;
    km[gac("j")] = 1602;
    km[gac("K")] = 1734;
    km[gac("k")] = 1603;
    km[gac("l")] = 1604;
    km[gac("m")] = 1605;
    km[gac("n")] = 1606;
    km[gac("o")] = 1608;
    km[gac("p")] = 1662;
    km[gac("q")] = 1670;
    km[gac("r")] = 1585;
    km[gac("s")] = 1587;
    km[gac("T")] = 1600;
    km[gac("t")] = 1578;
    km[gac("u")] = 1735;
    km[gac("v")] = 1736;
    km[gac("w")] = 1739;
    km[gac("x")] = 1588;
    km[gac("y")] = 1610;
    km[gac("z")] = 1586;
    km[gac("/")] = 1574;
    for (i = 0; i < km.length; i++) {
        if (km[i] != 0) {
            var u = gac(gas(i).toUpperCase());
            if (km[u] == 0) {
                km[u] = km[i]
            }
        }
    }
    km[gac(";")] = 1563;
    km[gac("?")] = 1567;
    km[gac(",")] = 1548;
    km[gac("<")] = 8250;
    km[gac(">")] = 8249;
    km[gac('"')] = OQUOTE;
    km[gac("{")] = gac("}");
    km[gac("}")] = gac("{");
    km[gac("[")] = gac("]");
    km[gac("]")] = gac("[");
    km[gac("(")] = gac(")");
    km[gac(")")] = gac("(");
    km[gac("}")] = 171;
    km[gac("{")] = 187;
    for (i = 0; i < cm.length; i++) {
        cm[i] = 0
    }
    cm[gac("a")] = 1575;
    cm[gac("b")] = 1576;
    cm[gac("c")] = 1603;
    cm[gac("d")] = 1583;
    cm[gac("e")] = 1749;
    cm[gac("f")] = 1601;
    cm[gac("g")] = 1711;
    cm[gac("h")] = 1726;
    cm[gac("i")] = 1609;
    cm[gac("j")] = 1580;
    cm[gac("k")] = 1603;
    cm[gac("l")] = 1604;
    cm[gac("m")] = 1605;
    cm[gac("n")] = 1606;
    cm[gac("o")] = 1608;
    cm[gac("p")] = 1662;
    cm[gac("q")] = 1602;
    cm[gac("r")] = 1585;
    cm[gac("s")] = 1587;
    cm[gac("t")] = 1578;
    cm[gac("u")] = 1735;
    cm[gac("v")] = 1739;
    cm[gac("w")] = 1739;
    cm[gac("x")] = 1582;
    cm[gac("y")] = 1610;
    cm[gac("z")] = 1586;
    cm[PRIMe] = 1744;
    cm[PRIME] = 1744;
    cm[COLo] = 1734;
    cm[COLO] = 1734;
    cm[COLu] = 1736;
    cm[COLU] = 1736;
    for (i = 0; i < cm.length; i++) {
        if (cm[i] != 0) {
            var u = gac(gas(i).toUpperCase());
            if (cm[u] == 0) {
                cm[u] = cm[i]
            }
        }
    }
    cm[gac(";")] = 1563;
    cm[gac("?")] = 1567;
    cm[gac(",")] = 1548
}

function ak2uni(akstr) {
    var str = akstr;
    var akdif = String.fromCharCode(1570, 1571, 1572, 1574, 1577, 1579, 1581, 1584, 1589, 1590, 1592, 1609, 1593, 1607, gac("{"), gac("}"));
    var akuni = String.fromCharCode(1688, 1734, 1739, 1744, 1749, 1709, 1670, 1735, 1662, 1711, 1574, 1736, 1609, 1726, CQUOTE, OQUOTE);
    for (var i = 0; i < akdif.length; i++) {
        str = str.replace(new RegExp(akdif.substr(i, 1), "g"), akuni.substr(i, 1))
    }
    return str
}

function uly2uy(ustr) {
    var str = "";
    var i, cur, prev, next, ch;
    var ccode, ncode;
    var wdbeg = true;
    var bd = "`";
    var ed = "`";
    var verbatim = false;
    var uly = ustr;
    var regExp = /(\w+[p|s]:\/\/\S*)/gi;
    uly = uly.replace(regExp, bd + "$1" + ed);
    regExp = /([\s|(]+\w+\.\w+\.\w+\S*)/g;
    uly = uly.replace(regExp, bd + "$1" + ed);
    regExp = /([\s|(|,|.]+\w+\.(com|net|org|cn)[\s|)|\.|,|.|$])/g;
    uly = uly.replace(regExp, bd + "$1" + ed);
    regExp = /(\w+@\w+\.\w[\w|\.]*\w)/g;
    uly = uly.replace(regExp, bd + "$1" + ed);
    if (!inited) {
        bedit_init()
    }
    for (i = 0; i < uly.length; i++) {
        ch = 0;
        cur = uly.charAt(i);
        next = uly.charAt(i + 1);
        ccode = uly.charCodeAt(i);
        ncode = uly.charCodeAt(i + 1);
        if (verbatim == true) {
            if (cur == ed) {
                verbatim = false
            } else {
                str += cur
            }
            continue
        }
        if (cur == bd) {
            verbatim = true;
            continue
        }
        if (cur == "|" && (prev == "u") && (next == "a" || next == "e")) {
            wdbeg = false;
            continue
        }
        if (wdbeg == true) {
            if (isvowel(cur)) {
                str += gas(HAMZA)
            }
        } else {
            if (cur == "'" || ccode == RCQUOTE) {
                if (isvowel(next)) {
                    wdbeg = false;
                    str += gas(HAMZA);
                    continue
                } else {
                    if (isalpha(ncode)) {
                        continue
                    }
                }
            }
        }
        if (isvowel(cur) || !isalpha(ccode)) {
            wdbeg = true
        } else {
            wdbeg = false
        }
        switch (cur) {
            case "c":
            case "C":
                if (next == "h" || next == "H") {
                    ch = CHEE
                }
                break;
            case "g":
            case "G":
                if (next == "h" || next == "H") {
                    ch = GHEE
                }
                break;
            case "n":
            case "N":
                if (next == "g" || next == "G") {
                    tmpch = uly.charAt(i + 2);
                    if (tmpch != "h" && tmpch != "H") {
                        ch = NGEE
                    }
                }
                break;
            case "s":
            case "S":
                if (next == "h" || next == "H") {
                    ch = SHEE
                } else {
                    if (next == "z" || next == "Z") {
                        ch = SZEE
                    }
                }
                break;
            default:
                break
        }
        if (ch != 0) {
            i++;
            str += gas(ch)
        } else {
            if (ccode < cm.length && cm[ccode]) {
                str += gas(cm[ccode])
            } else {
                str += gas(ccode)
            }
        }
        prev = cur
    }
    return str
}

function isvowel(ch) {
    var code = gac(ch);
    if (ch == "a" || ch == "e" || ch == "i" || ch == "o" || ch == "u" || ch == "A" || ch == "E" || ch == "I" || ch == "O" || ch == "U") {
        return true
    }
    if (code == PRIMe || code == PRIME || code == COLo || code == COLO || code == COLu || code == COLU) {
        return true
    }
    return false
}

function isalpha(code) {
    if ((gac("A") <= code && code <= gac("Z")) || (gac("a") <= code && code <= gac("z"))) {
        return true
    }
    return false
}

function AttachEvent(obj, evt, fnc, useCapture) {
    if (!useCapture) {
        useCapture = false
    }
    if (obj.addEventListener) {
        obj.removeEventListener(evt, fnc, useCapture);
        obj.addEventListener(evt, fnc, useCapture);
        return true
    } else {
        if (obj.attachEvent) {
            obj.detachEvent("on" + evt, fnc);
            return obj.attachEvent("on" + evt, fnc)
        }
    }
}

function attachEvents() {
    if (typeof (attachAll) == "undefined" || attachAll == null) {
        attachAll = false
    }
    if (typeof (bedit_allow) != "undefined" && bedit_allow && bedit_allow.length != 0) {
        allowed_names = bedit_allow.split(":")
    } else {
        allowed_names = new Array()
    }
    if (typeof (bedit_deny) != "undefined" && bedit_deny && bedit_deny.length != 0) {
        denied_names = bedit_deny.split(":")
    } else {
        denied_names = new Array()
    }
    var tas = document.getElementsByTagName("TEXTAREA");
    var tfs = document.getElementsByTagName("INPUT");
    for (i = 0; i < tas.length; i++) {
        if (shouldAttach(tas[i].name)) {
            AttachEvent(tas[i], "keypress", naddchar, false);
            AttachEvent(tas[i], "keydown", proc_kd, false)
        }
    }
    for (i = 0; i < tfs.length; i++) {
        if (tfs[i].type.toLowerCase() == "text" && shouldAttach(tfs[i].name)) {
            AttachEvent(tfs[i], "keypress", naddchar, false);
            AttachEvent(tfs[i], "keydown", proc_kd, false)
        }
    }
}

function shouldAttach(name) {
    var j;
    if (attachAll == true) {
        for (j = 0; j < denied_names.length; j++) {
            if (name == denied_names[j]) {
                return false
            }
        }
        return true
    } else {
        for (j = 0; j < allowed_names.length; j++) {
            if (name == allowed_names[j]) {
                return true
            }
        }
        return false
    }
}

if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", bedit_onLoad, false)
}
if (/WebKit/i.test(navigator.userAgent)) {
    var _timer = setInterval(function () {
        if (/loaded|complete/.test(document.readyState)) {
            bedit_onLoad()
        }
    }, 3000)
}
window.InitInputBox = function () {
    if (/WebKit/i.test(navigator.userAgent)) {

        if (/loaded|complete/.test(document.readyState)) {
            bedit_onLoad()
        }

    }
}
old_onLoad = null;
add_onLoad();

function add_onLoad() {
    old_onLoad = window.onload;
    window.onload = bedit_onLoad
}

function bedit_onLoad() {
    /* if (arguments.callee.done) {
         return
     }*/
    arguments.callee.done = true;
    /*if (_timer) {
        clearInterval(_timer)
    }*/
    bedit_init();
    attachEvents();
    if (old_onLoad) {
        old_onLoad()
    }
}

function addchar(content, event) {
    return naddchar(event)
}

function proc_kd_ctrl_k(source, ev) {
    imode = 1 - imode;
    return true
}

function proc_kd_ctrl_j(source, ev) {
    var t = gsel(source);
    if (t == "") {
        return false
    } else {
        ins(source, ak2uni(t));
        return true
    }
}
function proc_kd_ctrl_u(source, ev) {
    var t = gsel(source);
    if (t == "") {
        return false
    } else {
        ins(source, uly2uy(t));
        return true
    }
}
function proc_kd_ctrl_t(source, ev) {
    if (source.style.direction == "ltr") {
        source.style.direction = "rtl"
    } else {
        source.style.direction = "ltr"
    }
    return true
}

function proc_kd(event) {
    var x = false;

    var e = event ? event : window.event;
    e.keyCode ? e.keyCode : e.which;
    var s = e.srcElement ? e.srcElement : e.target;
    if (this._keydown != null) {
        this._keydown(event)
    }
    if (e.ctrlKey) {
        var f = false;
        for (var az = gac("A"); az <= gac("Z"); az++) {
            eval("if ( k == " + az + " && typeof proc_kd_ctrl_" + gas(az).toLowerCase() + ' == "function" ) { x = ' + "proc_kd_ctrl_" + gas(az).toLowerCase() + "(s, e); f=true;}");
            if (f) {
                break
            }
        }
    }
    if (x) {
        e.cancelBubble = true;
        if (e.preventDefault) {
            e.preventDefault()
        }
        if (e.stopPropagation) {
            e.stopPropagation()
        }
        e.returnValue = false;
        return false
    }
    return true
}

function gsel(source) {
    var s = source;
    if (document.all) {
        return document.selection.createRange().text
    } else {
        var ss = s.selectionStart;
        var se = s.selectionEnd;
        if (ss < se) {
            return s.value.substring(ss, se)
        }
    }
    return ""
}

function ins(source, str) {
    var s = source;
    if (document.selection && document.selection.createRange) {
        document.selection.createRange().text = str
    } else {
        var ss = s.selectionStart;
        var se = s.selectionEnd;
        var sTop, sLeft;
        if (s.type == "textarea" && typeof s.scrollTop != "undefined") {
            sTop = s.scrollTop;
            sLeft = s.scrollLeft
        }
        s.value = s.value.substring(0, ss) + str + s.value.substr(se);
        if (typeof sTop != "undefined") {
            s.scrollTop = sTop;
            s.scrollLeft = sLeft
        }
        s.setSelectionRange(ss + str.length, ss + str.length)
    }
}

function naddchar(event) {
    var e = event ? event : window.event;
    var k = e.keyCode ? e.keyCode : e.which;
    var s = e.srcElement ? e.srcElement : e.target;
    if (!inited) {
        bedit_init()
    }
    if (!e.ctrlKey && !e.metaKey && imode == 0 && k < km.length && km[k] != 0) {
        if (e.keyCode && !e.which) {
            e.keyCode = km[k]
        } else {
            ins(s, gas(km[k]));
            if (e.preventDefault) {
                e.preventDefault()
            }
            if (e.stopPropagation) {
                e.stopPropagation()
            }
        }
        if (k == gac('"')) {
            km[k] = qmode ? OQUOTE : CQUOTE;
            qmode = 1 - qmode
        }
        if (!e.keyCode || e.which) {
            return false
        }
    }
    if (/opera/i.test(navigator.userAgent) && e.ctrlKey) {
        var x = false;
        for (var az = gac("A"); az <= gac("Z"); az++) {
            eval("if(k == " + az + " && typeof proc_kd_ctrl_" + gas(az).toLowerCase() + ' == "function" ) { x = true }');
            if (x) {
                break
            }
        }
        if (x) {
            e.preventDefault();
            return false
        }
    }
    e.returnValue = true;
    return true
};